import json
import AnalysisJson
import Get
import os

db_name=''
qsql=''
ty=''
path=os.getcwd()
f0 = open(path+'//config.json', 'r')
try:
	for line in f0:
		print(line)
	config=json.loads(line)
	db_name=config['db_name']
	qsql=config['sql']
	if db_name.strip()=='' or qsql.strip()=='':
		print("配置文件异常")
		exit()
	if 'type' in config:
		ty=config['type']
	if ty!='sql' and ty!='excel':
		print("配置文件中没有说明导出文件类型")
finally:
	f0.close()
print('query sql :'+qsql)
print('database name :'+db_name)

httpGet = Get.Get()

data = httpGet.httpGet(qsql,db_name)
'''data= ''
f = open('f:/jsop.txt', 'r',encoding='utf8')
try:
    for line in f:
    	data=data+line
finally:
    f.close()'''

analys = AnalysisJson.AnalysisJson(data)
if ty == 'sql':
	analys.toInsertSql(path+'//sql.sql')
elif ty=='excel':
	analys.toExcel(path+"//sql.xls")
else:
    analys.toExcel(path+"//sql.xls")




